@extends('layouts.admin.application')

@section('content')
    <div class="main-content">
        <div class="col-xs-12">
            <div class="breadcrumbs" id="breadcrumbs">
                <ul class="breadcrumb">
                    <li><i class="icon-home home-icon"></i><a href="#">首页</a></li>
                    <li>用户管理</li>
                </ul>
            </div>
            <div class="table-responsive">
                <div id="sample-table-2_wrapper" class="dataTables_wrapper" role="grid">
                    <div class="row">

                        @include('layouts.partials._flash')

                        <div class="col-sm-2">
                            <div id="sample-table-2_length" class="dataTables_length">
                                <a href="{{ route('system.user.create') }}" class="btn btn-sm btn-primary">新增</a>
                            </div>
                        </div>

                        <form>
                            <div class="col-sm-10">
                                <div class="dataTables_filter" id="sample-table-2_filter">
                                    <label>
                                        用户名称:<input type="text" name="keyword" aria-controls="sample-table-2"
                                                    placeholder="按用户名称" value="{{Request::input('keyword')}}">
                                    </label>
                                    <label>
                                        <button type="submit" class="btn btn-xs btn-info" id="search">确定</button>
                                        <a href="{{ route('system.user.index') }}"
                                           class="btn btn-xs btn-default">重置</a>
                                    </label>
                                </div>
                            </div>
                        </form>

                    </div>
                    <table id="sample-table-2"
                           class="table table-striped table-bordered table-hover dataTable del-table"
                           aria-describedby="sample-table-2_info">
                        <thead>
                        <tr role="row">
                            <th>编号</th>
                            <th>用户名</th>
                            <th>所属用户组</th>
                            <th>邮箱</th>
                            <th>创建时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>

                        @foreach($users as $user)
                            <tr class="odd" data-id="{{$user->id}}">
                                <td>{{$user->id}}</td>
                                <td>{{$user->name}}</td>
                                <td>{{$user->roles->implode('name', ',')}}</td>
                                <td>{{$user->email}}</td>
                                <td>{{$user->created_at}}</td>
                                <td>
                                    <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                        <a class="green" href="{{route('system.user.edit', $user->id)}}">
                                            <i class="icon-pencil bigger-130"></i></a>

                                        @if($user->id != '1')
                                            <a class="red del_user" href="javascript:;">
                                                <i class="icon-trash bigger-130"></i>
                                            </a>
                                        @endif
                                    </div>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                    <div class="row">
                        <div class="col-sm-6">共 {{$users->total()}} 条记录</div>
                        <div class="col-sm-6">
                            <div class="dataTables_paginate paging_bootstrap">
                                <ul class="pagination">
                                    {{ $users->appends(Request::all())->links() }}
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script>
        $(function () {
            //ajax删除用户组
            $('.del_user').click(function () {
                var id = $(this).parents('tr').data('id');
                var _this = $(this);
                $.ajax({
                    type: 'delete',
                    url: '/admin/system/user/' + id,
                    data: id,
                    success: function () {
                        _this.parents('tr').fadeOut(400);
                    }
                });
                return false;
            })
        })
    </script>
@endsection